import {
    GETBANNERS,
    GETTOPLISTS,
    GETLISTDETAIL,
    GETRECOMMENDSONGCARD,
    GETRECOMMENDPROGRAM
} from "../constants";
import {
    getBannersAPI,
    getToplistsAPI,
    getListdetailAPI,
    getRecommendSongCardAPI,
    getRecommendProgramAPI
} from "../../api/home";

export const getBannersAction = (data) => {
    return async (dispatch) => {
        let res = await getBannersAPI();
        const data1 = res.data.banners;
        dispatch({
            type: GETBANNERS,
            data: data1
        });
    }
}

export const getRecommendSongCardAction = (data) => {
    return async (dispatch) => {
        let res = await getRecommendSongCardAPI();
        const data = res.data.playlists;
        dispatch({
            type: GETRECOMMENDSONGCARD,
            data
        })
    }
}

export const getRecommendProgramdAction = (data) => {
    return async (dispatch) => {
        let res = await getRecommendProgramAPI();
        const data = res.data.programs;
        dispatch({
            type: GETRECOMMENDPROGRAM,
            data
        });
        return data;
    }
}


export const getToplistsAction = () => {
    return async (dispatch) => {
        let res = await getToplistsAPI();
        const data = res.data.list;
        dispatch({
            type: GETTOPLISTS,
            data
        });
        return data; //方便获取数据
    }
}

export const getListdetailAction = (id) => {
    return async (dispatch) => {
        let res = await getListdetailAPI(id);
        const data = res.data;
        dispatch({
            type: GETLISTDETAIL,
            data
        })
    }
}